#pragma once

#include <QCalendarWidget>
#include <QColor>
#include <QFrame>
#include <QMouseEvent>
#include <QWidget>
#include <vector>

#include "SCalendar.h"
#include "widgets.h"

class QSpinBox;
class QMenu;
class DateSelected {
 public:
  std::vector<std::pair<QString, QDate>> m_dateSelected;
  int dateCountSelected() { return m_dateSelected.size(); };
  void clear() { m_dateSelected.clear(); };
};

class S_WIDGETS_EXPORT DualCalendars : public QFrame {
  Q_OBJECT
 public:
  explicit DualCalendars(QWidget* parent = nullptr, bool isSingle = false);
  ~DualCalendars();
  void setConnection();
  void setStartEndDate(QDate start, QDate end);
  void hideAfterSelected();
  void setInnerRect(QRect& rc) { m_rcInner = rc; }
  SCalendar* getLeftSCalendar() { return m_calL; }
  SCalendar* getRightSCalendar() { return m_calR; }

 signals:
  void dateSelected(int);
  void StartEndDatedSelected(int, int);

 protected:
  bool eventFilter(QObject* obj, QEvent* event);
  void paintEvent(QPaintEvent*) override;

 protected Q_SLOTS:
  void onrlClicked(std::pair<QString, QDate> info);
  void onMenuShow();
  void onMenuHide();

 private:
  bool m_isSingleMode = true;
  bool m_isShow = false;
  bool m_isMenuShow = false;
  SCalendar* m_calL = nullptr;
  SCalendar* m_calR = nullptr;
  DateSelected m_selectedDate;
  QMenu* m_calLmenu = nullptr;
  QMenu* m_calRmenu = nullptr;
  QRect m_rcInner;
};
